# -*- coding: utf-8 -*-
# @Create_time   :2023-08-26 15:00:00
# @Author        :kumiler
# @emial         :lukunming@jtexpress.com
# @File          :__init__.py
# @Desc          :

from datetime import timedelta
from utils.operators.cluster_for_spark_sql_operator import SparkSqlOperator

#Hive表名
hive_table_detail = "dm_spmi_center_piece_fee_report_detail_dt"
hive_table_aggr = "dm_spmi_center_piece_fee_report_aggr_dt"
#任务名
task_detail = f"spmi_dm__{hive_table_detail}"
task_aggr = f"spmi_dm__{hive_table_aggr}"

spmi_dm__dm_spmi_center_piece_fee_report_detail_dt = SparkSqlOperator(
    task_id=f'{task_detail}',
    task_concurrency=1,
    pool_slots=2,
    master='yarn',
    name=f'{task_detail}_{{{{ execution_date | date_add(1) | cst_ds }}}}',
    sql='spmi_analysis/dm/dm_spmi_center_piece_fee_report_dt/execute_detail.hql',
    retries=0,
    pool='spmi_piece',
    email=['lukunming@jtexpress.com', 'yl_bigdata@yl-scm.com'],
    execution_timeout=timedelta(hours=2),
    yarn_queue='pro',
    driver_memory='4G',
    driver_cores=2,
    executor_cores=5,
    executor_memory='10G',
    num_executors=60,  # spark.dynamicAllocation.enabled 为 True 时，num_executors 表示最少 Executor 数
    conf={'spark.dynamicAllocation.enabled': 'true',  # 动态资源开启
          'spark.shuffle.service.enabled': 'true',  # 动态资源 Shuffle 服务开启
          'spark.dynamicAllocation.maxExecutors': 80,  # 动态资源最大扩容 Executor 数
          'spark.dynamicAllocation.cachedExecutorIdleTimeout': 120,  # 动态资源自动释放闲置 Executor 的超时时间(s)
          'spark.sql.sources.partitionOverwriteMode': 'dynamic',  # 允许删改已存在的分区
          'spark.executor.memoryOverhead': '2G',  # 堆外内存
          'spark.sql.shuffle.partitions': 1200,
          },
    hiveconf={'hive.exec.dynamic.partition': 'true',  # 动态分区
              'hive.exec.dynamic.partition.mode': 'nonstrict',
              'hive.exec.max.dynamic.partitions': 80,
              'hive.exec.max.dynamic.partitions.pernode': 80,
              }
)



spmi_dm__dm_spmi_center_piece_fee_report_aggr_dt = SparkSqlOperator(
    task_id=f'{task_aggr}',
    task_concurrency=1,
    pool_slots=2,
    master='yarn',
    name=f'{task_aggr}_{{{{ execution_date | date_add(1) | cst_ds }}}}',
    sql='spmi_analysis/dm/dm_spmi_center_piece_fee_report_dt/execute_aggr.hql',
    retries=0,
    pool='spmi_piece',
    email=['lukunming@jtexpress.com', 'yl_bigdata@yl-scm.com'],
    execution_timeout=timedelta(hours=2),
    yarn_queue='pro',
    driver_memory='4G',
    driver_cores=2,
    executor_cores=4,
    executor_memory='10G',
    num_executors=40,  # spark.dynamicAllocation.enabled 为 True 时，num_executors 表示最少 Executor 数
    conf={'spark.dynamicAllocation.enabled': 'true',  # 动态资源开启
          'spark.shuffle.service.enabled': 'true',  # 动态资源 Shuffle 服务开启
          'spark.dynamicAllocation.maxExecutors': 60,  # 动态资源最大扩容 Executor 数
          'spark.dynamicAllocation.cachedExecutorIdleTimeout': 120,  # 动态资源自动释放闲置 Executor 的超时时间(s)
          'spark.sql.sources.partitionOverwriteMode': 'dynamic',  # 允许删改已存在的分区
          'spark.executor.memoryOverhead': '2G',  # 堆外内存
          'spark.sql.shuffle.partitions': 1000,
          },
    hiveconf={'hive.exec.dynamic.partition': 'true',  # 动态分区
              'hive.exec.dynamic.partition.mode': 'nonstrict',
              'hive.exec.max.dynamic.partitions': 80,
              'hive.exec.max.dynamic.partitions.pernode': 80,
              }
)

spmi_dm__dm_spmi_center_piece_fee_report_aggr_dt << spmi_dm__dm_spmi_center_piece_fee_report_detail_dt
